<template>
  <div class="home">
    <NavView></NavView>

    <div class="center container">
      <div class="center-left">
        <div class="content">
          <div class="box">
            <el-breadcrumb separator="/">
              <el-breadcrumb-item :to="{ path: '/' }">
                <i class="el-icon-s-home" style="margin-right: 10px"></i
                >首页</el-breadcrumb-item
              >
              <el-breadcrumb-item>正文</el-breadcrumb-item>
            </el-breadcrumb>
            <h1 class="h1">{{ form.title }}</h1>
            <p class="time">
              <span
                ><i class="el-icon-date"></i>发布于{{ form.updateTime }}</span
              ><span
                ><i class="el-icon-folder-opened"></i>分类于{{
                  form.categoryName
                }}</span
              >
              <span><i class="el-icon-view"></i>阅读量{{ form.readNum }}</span>
            </p>
            <p v-html="textTitle"></p>

            <span class="tag">
              <p v-for="(item, index) in form.tags" :key="index">
                <el-tag size="mini">{{ item.name }}</el-tag>
              </p>
            </span>
          </div>
          <div class="page">
            <div
              class="page-left Page"
              v-if="form.nextArticle !== null"
              @click="jump(form.nextArticle.id)"
            >
              <p><i class="el-icon-arrow-left"></i>上一篇</p>
              <p>{{ form.nextArticle.title }}</p>
            </div>
            <div
              class="page-right Page"
              v-if="form.preArticle != null"
              @click="jump(form.preArticle.id)"
            >
              <p>下一篇<i class="el-icon-arrow-right"></i></p>
              <p>{{ form.preArticle.title }}</p>
            </div>
          </div>
        </div>
      </div>

      <div class="center-right">
        <div class="admin">
          <AdminView></AdminView>
        </div>
        <div class="category" style="margin-top: 20px">
          <CateGory></CateGory>
        </div>
        <div id="tag" style="margin-top: 20px">
          <TagView></TagView>
        </div>
      </div>
    </div>

    <FooterView></FooterView>
    <router-view />
  </div>
</template>

<script>
export default {
  data() {
    return {
      id: "",
      form: {},
    };
  },
  computed: {
    textTitle() {
      return this.form.content; //计算属性，当this.form里面的内容动态修改时，其内容也会修改，
      //   进而影响到v-html绑定的内容
    },
  },
  methods: {
    jump(v) {
      this.$route.query.id = v;
      this.getText();
      // console.log("下一个内容", this.form.nextArticle);
      // console.log("上一个内容", this.form.preArticle);
    },
    getText() {
      this.$axios
        .post("http://47.104.167.34:9110/api/article/detail", {
          articleId: this.$route.query.id,
        })
        .then((r) => {
          if (r.data.data !== null) {
            this.form = r.data.data;
            console.log(r, "text-r", this.form);
          }
        });
    },
  },
  created() {
    this.getText();
  },
};
</script>

<style scoped>
.center {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.center-left {
  position: relative;
  width: 900px;
  /* height: 1800px; */
  /* background-color: antiquewhite; */
  margin: 20px 10px 0 0;
  border-radius: 10px;
}
.center-right {
  width: 290px;
  /* height: 1000px; */
  /* background-color: antiquewhite; */
  margin-top: 20px;
}
.content {
  width: 100%;
  height: 350px;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
  flex-direction: row;
  align-content: flex-start;
  --tw-bg-opacity: 1;
  background-color: rgb(255 255 255 / var(--tw-bg-opacity));
  padding: 20px;
  border-radius: 10px;
}
.admin {
  width: 290px;
  height: 220px;
}
.box {
  width: 100%;
  height: calc(100% - 60px);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: flex-start;
}
.page {
  width: 100%;
  height: 60px;
  border-top: 1px solid gainsboro;
}
.tag {
  display: flex;
}
.page {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.page > div {
  display: flex;
  flex-direction: column;
}
.h1 {
  word-wrap: break-word;
  font-size: 32px;
  font-weight: 700;
  color: #292525;
}
.time {
  width: 100%;
  font-size: 14px;
  color: rgb(129, 112, 112);
}
.time > span {
  margin-right: 10px;
}
.time span i {
  margin-right: 10px;
}
.el-tag {
  margin-right: 10px;
}
.Page p:nth-child(1) {
  font-size: 14px;
  color: rgb(129, 112, 112);
  margin-bottom: 10px;
}
.Page p:nth-child(2) {
  font-size: 16px;
  color: #000000ca;
}
</style>